package net.cherrylab.tools
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	import mx.core.FlexGlobals;
	import mx.core.UIComponent;
	
	import net.cherrylab.Event.ParticleEvent;
	import net.cherrylab.component.Ball;
	import net.cherrylab.manager.ParticleManager;

	/**
	 *一个单独的粒子效果，控制效果类型、坐标和范围
	 * 使用时实例化
	 * 
	 * @Auther Rolland Chen
	 * @Date 2010.10.19
	 * 
	 * */
	public class ParticleEffect extends UIComponent
	{
		private var _outsetPoint:Point=null;
		private var _targetPoint:Point=null;
		private var _targetArray:Array;
		private var _range:Rectangle;
		
		private var _radius:uint=0;
		private var _numParticles:int=10;
		
		private var _item:Sprite;
		private var _particles:Array;
		private var _type:String;
		private var _easing:Number;
		
		private var effectFun:Function;
		
		public function ParticleEffect(type:String,item:Sprite=null)
		{
			super();
			this.type=type;
			particles=new Array();
			addEventListener(ParticleEvent.PARTICLE_ENTERFRAME_EVENT,addEnterFrame);
		}
		
		public function play():void
		{
			//ParticleManager.CircleRange(this);
			//ParticleManager.PointToRange(this);
			//ParticleManager.PointFullScreen(this);
			ParticleManager.creatPartic(this);
			
		}
		
		private function init():void
		{
			
			
			
		}
		
		/**
		 * 添加ENTER_FRAME侦听
		 * */
		public function addEnterFrame(event:ParticleEvent):void
		{
			effectFun=event.fun;
			addEventListener(Event.ENTER_FRAME,onEnterFrame);
		}
		
		
		/**
		 * 删除ENTER_FRAME侦听
		 * */
		public function removeEnterFrame():void
		{
			removeEventListener(Event.ENTER_FRAME, onEnterFrame); 
			
		}
		
		private function onEnterFrame(event:Event):void
		{
			//ParticleManager.moveToPoint(this);
			if(effectFun!=null)
			{
				effectFun.call(null,this);
			}
			
		}

		
		
		/**
		 * 效果的起点
		 * */
		public function get outsetPoint():Point
		{
			return _outsetPoint;
		}

		/**
		 * @private
		 */
		public function set outsetPoint(value:Point):void
		{
			_outsetPoint = value;
		}

		/**
		 * 效果的目标点
		 * */
		public function get targetPoint():Point
		{
			return _targetPoint;
		}

		/**
		 * @private
		 */
		public function set targetPoint(value:Point):void
		{
			_targetPoint = value;
		}

		/**
		 * 效果范围
		 * */
		public function get range():Rectangle
		{
			return _range;
		}

		/**
		 * @private
		 */
		public function set range(value:Rectangle):void
		{
			_range = value;
		}

		/**
		 * 粒子数量
		 * */
		public function get numParticles():int
		{
			return _numParticles;
		}

		/**
		 * @private
		 */
		public function set numParticles(value:int):void
		{
			_numParticles = value;
		}

		/**
		 * 效果类型
		 * */
		public function get type():String
		{
			return _type;
		}

		/**
		 * @private
		 */
		public function set type(value:String):void
		{
			_type = value;
		}

		/**
		 * 粒子模型
		 * */
		public function get item():Sprite
		{
			return _item;
		}

		/**
		 * @private
		 */
		public function set item(value:Sprite):void
		{
			_item = value;
		}

		/**
		 * 范围半径
		 * */
		public function get radius():uint
		{
			return _radius;
		}

		/**
		 * @private
		 */
		public function set radius(value:uint):void
		{
			_radius = value;
		}

		/**
		 *粒子集合
		 * */
		public function get particles():Array
		{
			return _particles;
		}

		/**
		 * @private
		 */
		public function set particles(value:Array):void
		{
			_particles = value;
		}

		/**
		 * 缓动比例
		 * */
		public function get easing():Number
		{
			return _easing;
		}

		/**
		 * @private
		 */
		public function set easing(value:Number):void
		{
			_easing = value;
		}

		/**
		 * 目标点集合
		 * */
		public function get targetArray():Array
		{
			return _targetArray;
		}

		/**
		 * @private
		 */
		public function set targetArray(value:Array):void
		{
			_targetArray = value;
		}


	}
}